set phonedata = { }

# contacts data
phonedata.contacts = 	[ 
							first		|	last		|	group				|	birthday		|	fullbirthday	|	email				|	phone							
							'family1'	,	'member1'	,	'family'			,	mar 20 th		,	3/20/1979		,	johndoe1@mail.com	,	123-456-7891							
							'family2'  	,   'member2'	,	'family'			,	mar 25 th		,	3/25/1979		,	johndoe2@mail.com	,	123-456-7892
							'family2'  	,   'member3'	,	'family'			,	mar 20 th		,	3/20/1979		,	johndoe3@mail.com	,	123-456-7893
							'top1'  	,   'friend1'	,	'close friends'		,	feb 20 th		,	2/20/1979		,	johndoe4@mail.com	,	123-456-7894
							'top2'  	,   'friend1'	,	'close friends'		,	mar 6 th		,	3/6/1979		,	johndoe5@mail.com	,	123-456-7895
							'top3'  	,   'friend1'	,	'close friends'		,	feb 20 th		,	2/20/1979		,	johndoe6@mail.com	,	123-456-7896
							'john1'  	,   'doe1'		,	''					,	aug 20 th		,	7/20/1979		,	johndoe7@mail.com	,	123-456-7897
							'john2'  	,   'doe2'		,	''					,	aug 20 th		,	7/20/1979		,	johndoe8@mail.com	,	123-456-7898
							'john2'  	,   'doe3'		,	''					,	aug 20 th		,	7/20/1979		,	johndoe9@mail.com	,	123-456-7899
						]
						

# appointments data
phonedata.appointments = [
							title		|	date		|	time		
							'meeting 1' ,	3/10/2013   ,	8:30 am		
							'meeting 2' ,	3/10/2013   ,	8:30 am		
							'meeting 3' ,	3/10/2013   ,	8:30 am		
							'meeting 4' ,	3/12/2013   ,	8:30 am		
							'meeting 5' ,	3/12/2013   ,	8:30 am		
							'meeting 6' ,	3/12/2013   ,	8:30 am
							'meeting 7' ,	4/14/2013   ,	8:30 am		
							'meeting 8' ,	4/14/2013   ,	8:30 am		
							'meeting 9' ,	4/14/2013   ,	8:30 am		
						]						

# @summary: prints out each item in the table/list supplied
# @arg: name: table, type:table or list, required: yes
def printtable( table )
{
	for( row in table )
	{
		println( row.toString() )
	}
}			


def printresults()
{
	# print out the results just when debugging/testing
	# Note: you can specify multiple command line directives -directives:fakedata,debug
	println()
	println( "success: " + result.success )
	println( "message: " + result.message )
	println( " following records retrieved " )
	
	# Note: alternative syntax for with each <varname> in <collectionname>
	for(contact in result.data)
	{
		print( contact.name + ", " + contact.birthday + ', ' + contact.message )
	}
}
						
						
# @summary: gets contacts within a certain group
# @arg: name: group, type: text, required: yes,  examples: 'family'
def get_all_contacts_in_group ( group )
{
	# create variables contacts ( plural ) so we can automatically 
	# use the singular form contact in the where search
	contacts = phonedata.contacts	
	groupcontacts = contacts where contact.group is group
	return groupcontacts
}



# @summary: gets a contact by the phone number supplied.
# @arg: name: phone, type: text, required: yes,  examples: '123-456-7890'
def get_contact_by_phone ( phone )
{
	# create variables contacts ( plural ) so we can automatically 
	# use the singular form contact in the where search
	contacts = phonedata.contacts
	return contacts where contact.phone is phone
}


# @summary: gets a contact by the phone number supplied.
# @arg: name: firstname, type: text, required: yes,  examples: 'john'
# @arg: name: lastname, type: text, required: yes,  examples: 'doe1'
def get_contact_by_name ( firstname, lastname )
{
	# create variables contacts ( plural ) so we can automatically 
	# use the singular form contact in the where search
	contacts = phonedata.contacts
	return contacts where contact.first is firstname and contact.last is lastname
}


println loaded phonedata
printtable( phonedata.contacts )


